﻿using System;
using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;

namespace AUIP.Scripts.City.GameLogic {
    [ExecuteAlways]
    public class RoomIndicator : MonoBehaviour {
        [LabelText("房间名")]
        public string roomName;
        

        private void Start() {
            transform.name = roomName;
        }

#if UNITY_EDITOR
        private void OnEnable() {
            SceneView.duringSceneGui += OnSceneGUI;
        }

        private void OnDisable() {
            SceneView.duringSceneGui -= OnSceneGUI;
        }

        private const int MaxDistance = 80;
        private void OnSceneGUI(SceneView obj) {
            var distance = Vector3.Distance(SceneView.lastActiveSceneView.camera.transform.position,
                transform.position);

            if (distance > MaxDistance || !gameObject.activeInHierarchy) {
                return;
            }
            
            
            var style = new GUIStyle() {
                fontSize = 30,
                richText = true,
                alignment = TextAnchor.MiddleCenter
            };

            Handles.Label(transform.position, new GUIContent("<b><color=#00FFF0>" + roomName + "</color></b>"),style);
        }
#endif
    }
}